package com.css.fxfzaqbz.modules.data.controller;


import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.modules.data.entity.DisposeLabel;
import com.css.fxfzaqbz.modules.data.service.DisposeLabelService;
import com.css.fxfzaqbz.modules.supergraph.exception.CustomException;
import com.css.fxfzaqbz.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/fxfzaqbz/data")
@Slf4j
public class DisposeLabelController {

    @Resource
    DisposeLabelService disposeLabelService;

    /**
     * 保存新的标签
     *
     * @param disposeLabel 处置分析的标签信息
     * @return 处理结果
     */
    @PostMapping("/saveDisposeLabel")
    public RestResponse saveDisposeManager(@RequestBody DisposeLabel disposeLabel) {
        RestResponse restResponse = null;
        try {
            disposeLabelService.saveDisposeLabel(disposeLabel);
            restResponse = RestResponse.succeed();
        }catch (CustomException e) {
            log.error("新增处置分析子标签失败", e);
            restResponse = RestResponse.fail(e.getMessage());
        }catch (Exception e) {
            log.error("新增处置分析标签失败", e);
            restResponse = RestResponse.fail("新增处置分析标签失败!");
        }
        return restResponse;
    }


    /**
     * 根据 id 删除标签
     *
     * @param ids 标签id
     * @return
     */
    @PostMapping("/delDisposeLabel/{ids}")
    public RestResponse delDisposeLabel(@PathVariable("ids") List<String> ids) {
        RestResponse restResponse = null;
        try {
            disposeLabelService.delDisposeLabel(ids);
            restResponse = RestResponse.succeed();
        } catch (Exception e) {
            log.error("删除处置分析标签失败!", e);
            restResponse = RestResponse.fail("删除处置分析标签失败!");
        }
        return restResponse;
    }




    @GetMapping("/getDisposeAllLabel")
    public RestResponse getDisposeAllLabel(HttpServletRequest request,DisposeLabel disposeLabel) {
        RestResponse restResponse = null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize = Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            restResponse = RestResponse.succeed(disposeLabelService.getDisposeAllLabel(curPage,pageSize,disposeLabel));
        } catch (Exception e) {
            log.error("获取处置分析标签失败!", e);
            restResponse = RestResponse.fail("获取处置分析标签失败!");
        }
        return restResponse;
    }


}
